import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:bboy_music_box_2023/controllers/ctrl_home.dart';
import 'package:bboy_music_box_2023/controllers/ctrl_muisc.dart';
import 'package:bboy_music_box_2023/controllers/ctrl_play.dart';
import 'package:bboy_music_box_2023/controllers/ctrl_query.dart';
import 'package:bboy_music_box_2023/controllers/ctrl_upload.dart';
import 'package:bboy_music_box_2023/pages/page_home.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';

const String BASE_HOST = 'https://marklife.love';

void main() async {
  await GetStorage.init();
  // //顶部状态栏透明
  // SystemChrome.setSystemUIOverlayStyle(
  //     SystemUiOverlayStyle(statusBarColor: Colors.transparent));
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations([
    // 强制竖屏
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]);

  AwesomeNotifications().initialize(
    // set the icon to null if you want to use the default app icon
      'resource://drawable/res_app_icon',
      [
        NotificationChannel(
            channelGroupKey: 'basic_channel_group',
            channelKey: 'basic_channel',
            channelName: 'Basic notifications',
            channelDescription: 'Notification channel for basic tests',
            defaultColor: Color(0xFF9D50DD),
            ledColor: Colors.white)
      ],
      // Channel groups are only visual and are not required
      channelGroups: [
        NotificationChannelGroup(
            channelGroupKey: 'basic_channel_group',
            channelGroupName: 'Basic group')
      ],
      debug: true
  );

  runApp(
    GetMaterialApp(
      home: App(),
      routingCallback: (routing) {},
      onInit: () {
        Get.put(HomeCtrl());
        Get.put(QueryCtrl());
        Get.put(PlayCtrl());
        Get.put(UploadCtrl());
        Get.put(MusicCtrl());
        // Get.put(ScheduleCtrl());
        // Get.put(TrophyCtrl());
        // Get.put(StatisticCtrl());
      },
      theme: ThemeData(fontFamily: "MFont"),
      builder: (context, widget) {
        return MediaQuery(
          //设置文字大小不随系统设置改变
          data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
          child: widget!,
        );
      },
    ),
  );
}

class App extends StatefulWidget {
  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  void initState() {

    // Only after at least the action method is set, the notification events are delivered
    // AwesomeNotifications().setListeners(
    //     onActionReceivedMethod:         NotificationController.onActionReceivedMethod,
    //     onNotificationCreatedMethod:    NotificationController.onNotificationCreatedMethod,
    //     onNotificationDisplayedMethod:  NotificationController.onNotificationDisplayedMethod,
    //     onDismissActionReceivedMethod:  NotificationController.onDismissActionReceivedMethod
    // );

    AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
      if (!isAllowed) {
        // This is just a basic example. For real apps, you must show some
        // friendly dialog box before call the request method.
        // This is very important to not harm the user experience
        AwesomeNotifications().requestPermissionToSendNotifications();
      }
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return const HomePage();
  }
}

